import React from 'react';
import { Select, Spin } from 'antd';
import useGradeList from './useGradeList';

/**
 * 职级
 * 默认显示所有职级信息（包含删除）
 */
const AllGradeSelector = React.forwardRef(
    ({ query, setRankValue, value, onChange, dataSource, cacheKey = null, ...rest }, ref) => {
        const [loading, data] = useGradeList(dataSource, cacheKey);

        return (
            <Spin spinning={loading}>
                <Select
                    ref={ref}
                    placeholder="请选择"
                    value={value}
                    onChange={onChange}
                    optionFilterProp="children"
                    allowClear
                    getPopupContainer={trigger => trigger.parentElement}
                    {...rest}
                >
                    {data ? data.map(item => (
                        <Select.Option key={item.rankCode} value={item.rankCode}>
                            {item.rankValue}
                            {item.state === 1 ? ' (变更审批中)' : ''}
                            {item.state === 2 ? ' (变更待生效)' : ''}
                            <span style={{ color: 'red' }}>
                                {item.deleteFlag === 1 ? '（已删除）' : ''}
                            </span>
                        </Select.Option>
                    )) : null}
                </Select>
            </Spin>
        );
    }
);

export default AllGradeSelector;
